<template>
  <div class="component-root-container">
    <el-header>
      <el-form ref="projectRule" :rules="projectRule" :model="project" label-width="120px" label-position="right">
        <el-row>
          <el-col :span="8">
            <el-form-item label="订单编号:" prop="requestId">
              <el-input v-model="project['requestId']" placeholder="请输入订单编号" @input="change($event)" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8" class="col_button">
            <div class="button">
              <el-button class="query" @click="buttonClick">
                查询
              </el-button>
              <el-button class="query" @click="reset">
                重置
              </el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-header>

    <el-main>
      <div class="contentInfo" style="margin-bottom:20px;">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景使用情况
          </el-col>
        </el-row>
        <el-row>
          <div class="inline">
            <div><span>调用次数/日：</span><span>{{ query.count }}</span></div>
            <div><span>拦截比率：</span><span>{{ query.rate }}</span></div>
            <div><a class="link" href="javascript:;" @click="$router.push({name:'biz-ml'})">详情</a></div>
          </div>
        </el-row>
      </div>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景说明
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">在进行因存量历史站割接导致的集中操作服务终止时，检查该订单编号对应订单属性信息及站址下资产卡片累计原值，若订单属性为原产权方或既有共享方，同时站址下资产卡片累计原值为0，则审核通过并展示审核通过相关信息，否则审核不通过并展示不通过原因。</div>
          </div>
          <div class="page-tip">
            <div class="params-tip"><span>示例参数</span>：订单编号：1116071888143493</div>
          </div>
        </el-row>
      </div>
    </el-main>
    <el-main>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            校验结果
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">
              <div>{{ dialog.title }} </div>
              <el-row>
                <el-col>
                  {{ dialog.content || "" }}
                </el-col>
              </el-row>
            </div>
          </div>
        </el-row>
      </div>
    </el-main>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        dialogVisible: false,
        query:{
           count:0,
           rate:'--'
        },
        project: {
          requestId: ''
        },
        dialog: {
          title: '',
          content: ''
        },
        projectRule: {
          requestId: [{
            required: true,
            message: '请输入订单编号',
            trigger: 'blur'
          }]
        }
      }
    },
    created() {
      this.queryPageCount('2.14')
    },
    mounted() {},
    methods: {
      async buttonClick() {
        try {
          this.dialog = {
            title: '',
            content: ''
          }
          await this.$refs['projectRule'].validate()
          const data = {
            requestId: this.project['requestId'],
            serialNumber:'*',
            terminationReason:'*'
          }

          const r = await this.$http({
            url: this.$http.adornBizUrl('/existed/site/verification'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify(data), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          if (r.data.data) {
            var result = r.data.data[0];
            this.dialog.title = '订单编号：'+result.requestId;
            this.dialog.content = result.returnMsg || '无结果';
          }
        } catch (e) {
          console.log(e)
        } finally {
          this.listLoading = false
        }
      },
      reset() {
        this.project = {
          requestId: ''
        }
        this.dialog = {
          title: '',
          content: ''
        }
        this.$refs['projectRule'].clearValidate();
      },
      change(e) {
        this.$forceUpdate()
      },
      async queryPageCount(scene) {
        try {
          const r = await this.$http({
            url: this.$http.adornBizUrl('/log/queryStatistics'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify({scene:scene}), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          if(r.data.data && r.data.data.length >0){
              var result = r.data.data[0];
              this.query.count=result.cnt||'0';
              this.query.rate=(result.per==null?'--': (result.per*100).toFixed(1)+'%');
          }
        } catch (e) {
          console.log(e)
        } finally {
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "../../../assets/scss/_formatQueryPage";
  @include formatQueryPage(0, 60%, left);
  .el-input {
    width: 60%;
  }

  .query {
    color: rgba(255, 255, 255, 1);
    background: rgba(235, 75, 75, 1);
    border-radius: 6px;
    border-color: rgba(235, 75, 75, 1);
  }

  .custom-button {
    display: flex;
    justify-content: center;
  }
</style>
